<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/commons/jsp/taglibs.jsp"%>
<%@taglib uri="http://www.framework.com/taglib/tree" prefix="tree"%>
<%@taglib prefix="frame" uri="http://www.framework.com/taglib"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<OBJECT style="width: 0%; height: 0%;" classid="clsid:2B92874C-DCA6-4641-AEA5-BAEDE459B41C" height="0" width="0" size="0" id="AHCA" name="AHCA" codebase="#version=1,0,0,1" ></OBJECT>
<form name="addDataForm" id="addUserDataForm" method="post" action="${ctx}/framework/user/save">
	<input type="hidden" name="id" value="${user.id}"/>
	<input type="hidden" name="createTime" value="<fmt:formatDate value='${user.createTime}' pattern='yyyy-MM-dd HH:mm:ss'/>"/>
	<input type="hidden" name="createrId" value="${user.createrId}"/>
	<input type="hidden" name="createrName" value="${user.createrName}"/>
	<table class="infoTable">
		<tbody>
<!--		<tr>-->
<!--			<td width="20%" rowspan="5" align="center"><img id="xp" src="${ctx}/commons/images/sailor.png" width="100" alt="人员" title="人员" data="true"/></td>-->
<!--		</tr>-->
		<tr>
			<th align="right" width="10%">姓名</th>
			<td><input name="name" class="easyui-validatebox" size="15" value="${user.name}" data-options="required:true" maxlength="10"/>
			</td>
			<th align="right" width="10%">性别</th>
			<td>
				<c:choose>
				<c:when test="${empty user.sex}">
				<c:forEach items="${frame:dictChildren('sex')}" var="sex">
				<input type="radio" name="sex" value="${sex.value}" checked="checked"/>&nbsp;${sex.name}&nbsp;
				</c:forEach>
				</c:when>
				<c:otherwise>
					<c:forEach items="${frame:dictChildren('sex')}" var="sex">
						<c:choose>
						<c:when test="${user.sex==sex.value}">
						<input type="radio" name="sex" value="${sex.value}" checked="checked"/>&nbsp;${sex.name}&nbsp;
						</c:when>
						<c:otherwise>
							<input type="radio" name="sex" value="${sex.value}"/>&nbsp;${sex.name}&nbsp;
						</c:otherwise>
						</c:choose>
					</c:forEach>
				</c:otherwise>
			</c:choose>
			</td>
		</tr>
		<tr>
			<th align="right" width="10%">登录名</th>
			<td>
					<input name="loginName" class="easyui-validatebox" size="15" value="${user.loginName}" data-options="required:true,validType:['unsafe','unique[\'${ctx}\',\'T_SYS_USER_INFO\',\'LOGIN_NAME\',\'${user.id }\']']" maxlength="30"/>
			</td>
			<input type="hidden" name="psw" value="123456"/>
			<!--  <th align="right" width="10%">密码</th>
			<td><input type="password" name="psw" class="easyui-validatebox" size="15" value="${user.psw}" data-options="required:true,validType:['isNull','minLength[6]']" maxlength="6"/>
			</td>-->
			<th align="right" width="10%">出生日期</th>
			<td><input class="easyui-datebox" name="birthday" value="<fmt:formatDate pattern="yyyy-MM-dd" value="${user.birthday}" />" data-options="validType:['date']" style="width:116px">
			</td>
		</tr>
		<tr>
			<th align="right" width="10%">联系电话</th>
			<td><input name="tel" class="easyui-validatebox" size="15" value="${user.tel}" data-options="required:true,validType:['phone']" maxlength="20"/>
			</td>
			<th align="right" width="10%">手机号码</th>
			<td><input name="mobile" class="easyui-validatebox" size="15" value="${user.mobile}" data-options="required:true,validType:['mobile']" maxlength="11"/>
			</td>
		</tr>
		<tr>
			
			<th align="right" width="10%">邮编</th>
			<td><input name="post" class="easyui-validatebox" size="15" value="${user.post}" data-options="validType:['number']" maxlength="6"/>
			</td>
			<th align="right" width="10%">地址</th>
			<td><input name="address" class="easyui-validatebox" size="15" value="${user.address}" maxlength="128"/>
			</td>
		</tr>
		<tr>
			<th align="right" width="10%">EMAIL</th>
			<td><input name="email" class="easyui-validatebox" size="15" value="${user.email}" data-options="validType:['email']" maxlength="50"/>
			</td>
			<th align="right" width="10%">CA_CARD</th>
			<td><input name="caCard" id="caName" class="easyui-validatebox" size="15" value="${user.caCard}" maxlength="50"/><a href="javascript:void(0);" onclick="getCaCard();" class="easyui-linkbutton" plain="true">获得CA值</a>
			</td>
		</tr>
	
	 	<tr>
			<th align="right" width="10%">部门</th>
			<td><input name="deptName" id="deptName" class="easyui-validatebox" size="15" readonly="readonly" data-options="required:true" value="${user.deptName}"/>
			<input type="hidden" name="deptId" id="deptId" class="easyui-validatebox" size="30" value="${user.deptId}"/>
			<span id="pDept" style="width: 100px;height: 100px;"><a href="javascript:void(0);" onclick="selectDept()"><img src="${ctx}/commons/themes/icons/icon3.gif" border="0" title="所属部门"/></a></span>
			</td>
			<th align="right" width="10%">部门信息</th>
			<td><input name="deptMsg" class="easyui-validatebox" size="15" value="${user.deptMsg}" data-options="validType:['deptMsg']" maxlength="512"/>
			</td>
		</tr>
		<!--  	<tr>
			<th align="right" width="10%">用户类型</th>	
			<td>
			<select id="userType" name="type" style="width:140px;" data-options="panelHeight:100,required:true">
				<c:forEach items="${frame:dictChildren('user_type')}" var="type">
					<c:choose>
						<c:when test="${sessionScope.loginUser.id == '1'}"><option value="${type.value}" <c:if test="${user.type == type.value}">selected="selected"</c:if> >${type.name}</option></c:when>
						<c:when test="${sessionScope.loginUser.id != '1' && type.value != '1'}"><option value="${type.value}" <c:if test="${user.type == type.value}">selected="selected"</c:if> >${type.name}</option></c:when>
					</c:choose>
				</c:forEach>
			</select>
			
			</td>	
			
		</tr>-->
		</tbody>
		<input id="getIspNum" type="hidden" value="${user.ispNum}"/>
	</table>
		<tree:deptTree ctx="${ctx}" deptIds="deptId" deptNames="deptName" selectMethod="single" />
</form>
<script type="text/javascript">
	$(document).ready(function () {
	var userTypeValue=$('#userType').attr("value");
	if(userTypeValue==1){
		var getIspNum=$('#getIspNum').attr("value");
		document.getElementById('supplierCode').style.display="";
		var showDoc = '<input id="ispNum" name="ispNum" class="easyui-validatebox" size="15" value="'+getIspNum+'" data-options="required:true,validType:[\'unsafe\',\'minLength[0]\',\'unique[\\\'${ctx}\\\',\\\'T_SYS_USER_INFO\\\',\\\'ISP_NUM\\\',\\\'${user.id }\\\']\']" maxlength="10"/>';//,\'unique[\'${ctx}\',\'T_SYS_USER_INFO\',\'ISP_NUM\',\'${user.ispNum }\',\'${user.id }\']\'
		$("#parentDom").append(showDoc);
		$.parser.parse("#parentDom");
	}
		 $('#userType').combobox({
                onChange: function (n,o) {
                   if(n==1){
						document.getElementById('supplierCode').style.display="";
						var showDoc = '<input id="ispNum" name="ispNum" class="easyui-validatebox" size="15" value="${user.ispNum }" data-options="required:true,validType:[\'unsafe\',\'minLength[0]\',\'unique[\\\'${ctx}\\\',\\\'T_SYS_USER_INFO\\\',\\\'ISP_NUM\\\',\\\'${user.id }\\\']\']" maxlength="10"/>';//,\'unique[\'${ctx}\',\'T_SYS_USER_INFO\',\'ISP_NUM\',\'${user.ispNum }\',\'${user.id }\']\'
						$("#parentDom").append(showDoc);
						$.parser.parse("#parentDom");
                   }else{
                   		document.getElementById('supplierCode').style.display="none";
	                   $("#ispNum").remove();
	                   
                   }
                   
                }
            });
             
	});

	function getCaCard(){
		var rs;
		try{
			AHCA.ClearPasswd();
			rs = AHCA.setPasswd('P11', '123456', 1);		
		}catch(e){
			alert('error');	
			return;
		}
		if(!rs)
		{
			var errorMsg = AHCA.GetLastErrorInfo(0);
			errorMsg += '\n请确认安徽CA的UKEY是否正确插入，或密码是否正确！';
			alert(errorMsg);
			return;
		}
		var yxqts = -1;
		var strClientCert = AHCA.GetCertEx(2);
		
		if('' == strClientCert)
		{
			alert("证书获取异常！");
			return;
		}
		var clientCajgdm = AHCA.GetCertInfo(strClientCert, 2007, '');
		if('AHCARSA' != clientCajgdm){
			alert("插入的不是安徽ca发的KEY");
		}
		
		var caName = AHCA.GetCertInfo(strClientCert, 3007, '');

		rs = AHCA.VerifyCert(strClientCert);
		if(!rs)
		{
			alert("证书有效性验证异常！");
			return;
		}

		
		//3.4剩余天数提醒
		rs = AHCA.GetCertInfo(strClientCert, 3043, '');

		if('' == rs)
		{
			alert("剩余天数获取异常!");
			return;
		}
		
		if('' == rs)
		{
			alert("剩余天数获取异常!");
			return;
		}
		else
		{
			if(rs<=0){
				alert('您的数字证书已过期，请升级数字证书后再登录系统！');
				return;
			}
		}
		$('#caName').val(caName);
	}

	function selectDept(){
		seldeptIdDeptTree($('#deptId').val());
		$('#deptIdDeptTreeDialog').dialog('open');
	}
//	function selectPost(){
//		selpostIdPostTree($('#postId').val());
//		$('#postIdPostTreeDialog').dialog('open');
//	}
</script>
